﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LoanMessages;
using PServiceBus.Services.Gateway.Runtime;
using PServiceBus.MessageProxy;

namespace LoanBroker {
    class Program {
        static Random _random = new Random();
        static void Main(string[] args) {
            ProxyService.Start();

            var service = ProxyService.Create<ILoanService>();

            Console.WriteLine("Press enter to send quote request. Type exit to end loan broker");


            while (true) {
                var text = Console.ReadLine();
                if (text.ToLower() == "exit") {
                    break;
                }
                //Make Loan Request
                
                var loan = new LoanRequest()
                {
                    SSN = _random.Next(100) + 9,
                    LoanTerm = _random.Next(75) + 1,
                    LoanAmount = (_random.Next(10000) + 1) * 3
                };

                Console.WriteLine("Sending loan request....");

                var response = service.GetLoan(loan);

                if (response != null)
                    Console.WriteLine("Received Best quote {0} {1}",
                          response.InterestRate, response.QuoteID);
                else
                    Console.WriteLine("Could not get quote");
            }

            ProxyService.Shutdown();
        }
    }
}
